package mapreduce;

import java.util.Vector;
import mapreduce.pair;


public class MapBufferManager<KEYIN, VALUEIN, KEYOUT, VALUEOUT> extends BufferManager<KEYIN, VALUEIN, KEYOUT, VALUEOUT> {
	private Vector<pair<KEYOUT, VALUEOUT>>[][] map;
	private int reducenum;
	public MapBufferManager(int taskid, Vector<pair<KEYOUT, VALUEOUT>>[][] map, int reducenum)
	{
		super(taskid);
		this.reducenum = reducenum;
		this.map =map;
//		System.out.println("map len="+map.length);
	}
	@Override
	public void write(KEYOUT key, VALUEOUT value) {
		// TODO Auto-generated method stub
		int len= map.length;
		int wid= map[Taskid].length;
		int num= Math.abs(key.toString().hashCode()%reducenum);
		try {
			pair<KEYOUT, VALUEOUT> p =new pair(key, value);
			map[Taskid][num].add(p);
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("error:"+e.getMessage());
		}
		
	}

	@Override
	public void close() {
		// TODO Auto-generated method stub
		
	}

}
